import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    islogin:sessionStorage.getItem('islogin'),  //保存是否已登录
    username: sessionStorage.getItem('username'),  //保存当前登录的用户名
  },
  mutations: {
    /*登录成功后调用
      修改登录状态， 将传入的单签登录用户存入state
    */
    loginok(state,name){
      state.islogin = true;
      state.username = name;
    }
  },
  actions: {//异步修改状态
    login(store,payload){
      this.axios.post('/login','paylaod').then(res=>{
        if(res.data.code == 200){
          store.commit('loginok','用户名')
        }
      })
    }
  },
  /* 调用：
    this.$store.dispatch('login',{name:'zhangsan',pwd:'123456'});
  */
  modules: {
  }
})
